<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of CtHoaDonDAO
 *
 * @author HOANGPHUC
 */
require ("../ENTITY/CtHoaDon.php");
class CtHoaDonDAO {

    public function __construct() {
        require ("../UTIL/MySQLProvider.php");
//        require ("../ENTITY/CtHoaDonDAO.php");

    }

    public static  function Create($column, $value) {

        $dbHandle = new MySQLProvider();
        $flag = $dbHandle->Insert("ct_hoadon", $column, $value);
        $dbHandle->CloseConnection();
        return $flag;
    }

    public static function Edit($column, $value, $whereColumn, $whereValue) {
        //require ("/UTIL/MySQLProvider.php");
        $dbHandle = new MySQLProvider();
        $flag = $dbHandle->Update("ct_hoadon", $column, $value, $whereColumn, $whereValue);
        $dbHandle->CloseConnection();
        return $flag;
    }

    public static function Remove($whereColumn, $whereValue) {
        // require ("/UTIL/MySQLProvider.php");
        $dbHandle = new MySQLProvider();
        $flag = $dbHandle->Delete("ct_hoadon", $whereColumn, $whereValue);
        $dbHandle->CloseConnection();
        return $flag;
    }

    public static function findAll() {
        // require ("/UTIL/MySQLProvider.php");

        $dbHandle = new MySQLProvider();
        $result = $dbHandle->GetResultSet("select * from ct_hoadon");
        $arr = array();
        $i = 0;

        while ($r = mysql_fetch_array($result)) {

            $theLoai = new CtHoaDon();
            $theLoai->SetHoaDon($r['MAHOADON']);
            $theLoai->SetTranh($r['MATRANH']);
            $theLoai->SetMoTa($r['SOLUONG']);
            $theLoai->SetTenEn($r['TONGTIEN']);
            $theLoai->SetMoTaEn($r['GHICHU']);
            $arr[$i] = $theLoai;
            $i++;
        }
        $dbHandle->CloseConnection();
        return $arr;
    }

    public static function findByHoaDon($maHoaDon) {
        $dbHandle = new MySQLProvider();
        $result = $dbHandle->GetResultSet("select * from ct_hoadon where mahoadon =" .$maHoaDon);
        $arr = array();
        $i = 0;

        while ($r = mysql_fetch_array($result)) {

            $theLoai = new CtHoaDon();
            $theLoai->SetHoaDon($r['MAHOADON']);
            $theLoai->SetTranh($r['MATRANH']);
            $theLoai->SetMoTa($r['SOLUONG']);
            $theLoai->SetTenEn($r['TONGTIEN']);
            $theLoai->SetMoTaEn($r['GHICHU']);
            $arr[$i] = $theLoai;
            $i++;
        }
        $dbHandle->CloseConnection();
        return $arr;
    }

}

?>
